package com.anyou.mall.partner.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.core.page.TableDataInfo;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.mall.partner.domain.PartnerLavel;
import com.anyou.mall.partner.service.IPartnerLavelService;
import com.anyou.mall.parts.domain.PlaPartsClassify;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 合伙人等级Controller
 *
 * @author ruoyi
 * @date 2023-10-10
 */
@Api(tags = "合伙人等级")
@RestController
@RequestMapping("/partner/lavel")
public class PartnerLavelController extends BaseController
{
    @Autowired
    private IPartnerLavelService partnerLavelService;


    /**
     * 查询合伙人等级列表
     */
    @ApiOperation("查询合伙人等级列表")
    @PreAuthorize("@ss.hasPermi('partner:lavel:list')")
    @GetMapping("/list")
    public TableDataInfo<List<PartnerLavel>> list(PartnerLavel partnerLavel)
    {
        startPage();
        List<PartnerLavel> list = partnerLavelService.selectPartnerLavelList(partnerLavel);
        return getDataTable(list);
    }
    /**
     * 可用商品分类下拉列表
     * 只查一级分类
     */
    @ApiOperation("可用商品分类下拉列表")
    @PreAuthorize("@ss.hasPermi('partner:lavel:goodsTypeList')")
    @GetMapping("/goodsTypeList")
    public ApiResult<List<PlaPartsClassify>> goodsTypeList()
    {
        List<PlaPartsClassify> list = partnerLavelService.goodsTypeList();
        return ApiResult.success(list);
    }

    /**
     * 导出合伙人等级列表
     */
    @ApiOperation("导出合伙人等级列表")
    @PreAuthorize("@ss.hasPermi('partner:lavel:export')")
    @Log(title = "合伙人等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartnerLavel partnerLavel)
    {
        List<PartnerLavel> list = partnerLavelService.selectPartnerLavelList(partnerLavel);
        ExcelUtil<PartnerLavel> util = new ExcelUtil<PartnerLavel>(PartnerLavel.class);
        util.exportExcel(response, list, "合伙人等级数据");
    }

    /**
     * 获取合伙人等级详细信息
     */
    @ApiOperation("获取合伙人等级详细信息")
    @PreAuthorize("@ss.hasPermi('partner:lavel:query')")
    @GetMapping(value = "/{lavelId}")
    public ApiResult<PartnerLavel> getInfo(@PathVariable("lavelId") Long lavelId)
    {
        return ApiResult.success(partnerLavelService.selectPartnerLavelByLavelId(lavelId));
    }

    /**
     * 新增合伙人等级
     */
    @ApiOperation("新增合伙人等级")
    @PreAuthorize("@ss.hasPermi('partner:lavel:add')")
    @Log(title = "合伙人等级", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody PartnerLavel partnerLavel)
    {
        return ApiResult.success(partnerLavelService.insertPartnerLavel(partnerLavel));
    }

    /**
     * 修改合伙人等级
     */
    @ApiOperation("修改合伙人等级")
    @PreAuthorize("@ss.hasPermi('partner:lavel:edit')")
    @Log(title = "合伙人等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody PartnerLavel partnerLavel)
    {
        return ApiResult.success(partnerLavelService.updatePartnerLavel(partnerLavel));
    }

    /**
     * 删除合伙人等级
     */
    @ApiOperation("删除合伙人等级")
    @PreAuthorize("@ss.hasPermi('partner:lavel:remove')")
    @Log(title = "合伙人等级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lavelIds}")
    public ApiResult remove(@PathVariable Long[] lavelIds)
    {
        return ApiResult.success(partnerLavelService.deletePartnerLavelByLavelIds(lavelIds));
    }
}
